<template>
    <div>
        <p>时间范围<el-time-picker class="order-input" is-range v-model="time" range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" placeholder="选择时间范围">
  </el-time-picker><el-button type="primary">查询</el-button></p>
   <div class="data-box" id="chart"></div>
    </div>
</template>

<script>
import * as echarts from 'echarts';

    export default {
        data(){
            return{
                 time: [new Date(2021, 1, 10, 8, 40), new Date(2021, 3, 10, 9, 40)],
            }
        },
        methods:{
            generateData(count) {
    var baseValue = Math.random() * 1000;
    var time = +new Date(2011, 0, 1);
    var smallBaseValue;

    function next(idx) {
        smallBaseValue = idx % 30 === 0
            ? Math.random() * 700
            : (smallBaseValue + Math.random() * 500 - 250);
        baseValue += Math.random() * 20 - 10;
        return Math.max(
            0,
            Math.round(baseValue + smallBaseValue) + 3000
        );
    }

    var categoryData = [];
    var valueData = [];

    for (var i = 0; i < count; i++) {
        categoryData.push(echarts.format.formatTime('yyyy-MM-dd\nhh:mm:ss', time));
        valueData.push(next(i).toFixed(2));
        time += 1000;
    }

    return {
        categoryData: categoryData,
        valueData: valueData
    };
}
        },
        mounted(){
            let myChart = echarts.init(document.getElementById('chart'));
            var dataCount = 5e5;
            var data = this.generateData(dataCount);
            myChart.setOption({
    title: {
        text: '商品统计',
        left: 10
    },
    toolbox: {
        feature: {
            dataZoom: {
                yAxisIndex: false
            },
            saveAsImage: {
                pixelRatio: 2
            }
        }
    },
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'shadow'
        }
    },
    grid: {
        bottom: 90
    },
    dataZoom: [{
        type: 'inside'
    }, {
        type: 'slider'
    }],
    xAxis: {
        data: data.categoryData,
        silent: false,
        splitLine: {
            show: false
        },
        splitArea: {
            show: false
        }
    },
    yAxis: {
        splitArea: {
            show: false
        }
    },
    series: [{
        type: 'bar',
        data: data.valueData,
        // Set `large` for large data amount
        large: true
    }]
})
        },
        
    }
</script>

<style lang="less" scoped>
.order-input{
    margin: 0 5px;
}
p{
    margin-top: 20px;
    margin-bottom: 50px;
}
.data-box{
    width: 95%;
    height: 500px;
}
</style>